package netty.study.fourth.server;

import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.timeout.IdleState;
import io.netty.handler.timeout.IdleStateEvent;
import io.netty.util.concurrent.EventExecutorGroup;

/**
 * @author songZiHao
 * @version 1.0.0
 * @ClassName MyServerHander.java
 * @Description TODO
 * @createTime 2020年04月17日 17:06:00
 */
public class MyServerHandler extends ChannelInboundHandlerAdapter {
	//触发evt后，执行这个逻辑
	@Override
	public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
		String eventType = null;
		if (evt instanceof IdleStateEvent) {
			IdleStateEvent event = (IdleStateEvent) evt;
			switch (event.state()) {
				case ALL_IDLE:
					eventType = "读写空闲";
					break;
				case READER_IDLE:
					eventType = "读空闲";
					break;
				case WRITER_IDLE:
					eventType = "写空闲";
					break;
				default:
					eventType = "";
			}
		}
		System.out.println(ctx.channel().remoteAddress() + "超时事件" + eventType);
		ctx.channel().close();
	}
}
